<?php
/**
 * useage:
 * throw new qsf_Exception('报错信息', );
 */
class qsf_Exception extends Exception {
	protected $description;

	/**
	 * Creates a new system_exception
	 *
	 * @param	string		$message	error message
	 * @param	integer		$code		error code
	 * @param	string		$description	description of the error
	 */
	public function __construct($message = '', $description = '') {
		parent::__construct ( $message, 0 );
		$this->description = $description;
	}

	/**
	 * Returns the description of this exception.
	 *
	 * @return 	string
	 */
	public function getDescription() {
		return $this->description;
	}

	/**
	 * Removes database password from stack trace.
	 * @see Exception::getTraceAsString()
	 */
	public function __getTraceAsString() {
		return $this->getTraceAsString ();
	}

	/**
	 * Prints this exception.
	 *
	 */
	public function show() {
		if(defined('DEBUG') && DEBUG){
			$this->errorSystem();
		} else {
			$this->errorFriendly();
		}
	}

	protected function errorSystem() {
		?>
		<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
		<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" xml:lang="en">
		<head>
		<title>当您看到这个页面是，代表着网站出现了一个严重的错误:</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<style type="text/css">
		.systemException { border: 1px outset lightgrey; padding: 3px; background-color: lightgrey; text-align: left; overflow: auto; font-family: Verdana, Helvetica, sans-serif; font-size: .8em; }
		.systemException div { border: 1px inset lightgrey; padding: 4px; }
		.systemException h1 { background-color: #154268; padding: 4px; color: #fff; margin: 0 0 3px 0; font-size: 1.15em; }
		.systemException h2 { font-size: 1.1em; margin-bottom: 0; }
		.systemException pre, .systemException p { margin: 0; }
		.systemException pre { font-size: .85em; font-family: "Courier New"; }
		</style>
		</head>
		<body>
		<div class="systemException">
			<h1>当您看到这个页面是，代表着网站出现了一个严重的错误:</h1>
				<div>
				<!-- <p><?php echo $this->getDescription(); ?></p> -->
				<h2>详细错误信息如下:</h2>
				<p><b>信息:</b> <?php echo htmlspecialchars($this->getMessage()); ?><br />
				<b>文件:</b> <?php echo htmlspecialchars($this->getFile()); ?> (<?php echo $this->getLine(); ?>)<br />
				<b>PHP版本:</b> <?php echo htmlspecialchars(phpversion()); ?><br />
				<b>时间:</b> <?php echo gmdate('r'); ?><br />
				<b>请求页:</b> <?php if (isset($_SERVER ['REQUEST_URI'])) echo htmlspecialchars($_SERVER ['REQUEST_URI']); ?><br />
				<b>来源页:</b> <?php if (isset($_SERVER ['HTTP_REFERER'])) echo htmlspecialchars($_SERVER ['HTTP_REFERER']); ?><br />
				</p>
				<h2>跟踪:</h2>
				<pre><?php echo htmlspecialchars($this->__getTraceAsString()); ?></pre>
			</div>
		</div>
		</body>
		</html>
		<?php
	}


	protected function errorFriendly(){
            echo '系统错误，请联系网站管理员。';
	}

}